<!--title-->
<div class="mnav1">
	<div class="m_nav">
		<div class="nav_left">
			<em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
		</div>
	</div>
</div>

<div class="content-table">
<div class="content-table-title"><?=$this->title?></div>
<br />
<?php if($this->msg):?>
<div class="replace"><?=$this->msg?></div>
<br />
<?php endif;?>
<div class="form-edit-task">

<?php
$total_qty = 0;

foreach($this->sku_info['base_info'] as $val)
{
	$total_qty += $val['quantity'];
}	
?>
	
<table border="1" width="100%">
	<tr>
		<td align="right">合同状态：</td>
		<td align="left">&nbsp;<?=$this->contract_info['delivery_status_name']?></td>
	</tr>
	<tr>
		<td align="right" width="30%">合同编号：</td>
		<td align="left">&nbsp;<?=$this->contract_info['contract_sid']?></td>
	</tr>
	<tr>
		<td align="right" width="30%">客户全称：</td>
		<td align="left">&nbsp;<?=$this->client_info['client_name']?></td>
	</tr>
	<?php if($this->client_info['additional_info']['brand_info']['str']):?>
	<tr>
		<td align="right" width="30%">品牌：</td>
		<td align="left">&nbsp;<?=$this->client_info['additional_info']['brand_info']['str']?></td>
	</tr>
	<?php endif;?>
	<?php if($this->client_info['additional_info']['channel_info']['str']):?>
	<tr>
		<td align="right" width="30%">渠道：</td>
		<td align="left">&nbsp;<?=$this->client_info['additional_info']['channel_info']['str']?></td>
	</tr>
	<?php endif;?>
	<?php if($this->client_info['additional_info']['factory_info']['str']):?>
	<tr>
		<td align="right" width="30%">厂商：</td>
		<td align="left">&nbsp;<?=$this->client_info['additional_info']['factory_info']['str']?></td>
	</tr>
	<?php endif;?>
	<tr>
		<td align="right">签约公司：</td>
		<td align="left">&nbsp;<?=$this->contract_info['signer_company_name']?$this->contract_info['signer_company_name']:$this->contract_info['client_name']?></td>
	</tr>
	<tr>
		<td align="right">乙方单位：</td>
		<td align="left">&nbsp;<?=$this->contract_info['owner_name']?></td>
	</tr>
	<tr>
		<td align="right" width="30%">销售顾问：</td>
		<td align="left">&nbsp;<?=$this->contract_info['sales_emp_name']?></td>
	</tr>
	<tr>
		<td align="right">起止日期：</td>
		<td align="left">&nbsp;<?=$this->contract_info['start_date']?> 至 <?=$this->contract_info['expired_date']?>
		</td>
	</tr>
	<tr>
		<td align="right">折扣：</td>
		<td align="left">&nbsp;<?=round($this->contract_info['receivable_value']/($this->contract_info['contract_claim_amount']*2)*100)."%"?></td>
	</tr>
	<tr>
		<td align="right">付款方式：</td>
		<td align="left">&nbsp;<?php if(1==$this->contract_info['pay_type']){echo "预付";}elseif(2==$this->contract_info['pay_type']){echo "后付";}elseif(3==$this->contract_info['pay_type']){echo "分期";}elseif(4==$this->contract_info['pay_type']){echo "免费";}?><?php if(2==$this->contract_info['pay_type']):?>&nbsp;&nbsp;&nbsp;&nbsp;(回款日期：<?=$this->contract_info['pay_date']?>)<?php endif;?></td>
	</tr>
	<tr>
		<td align="right">合同备注：</td>
		<td align="left">&nbsp;<?=$this->contract_info['tips']?"<font color='red'>".$this->contract_info['tips']."</font>":""?></td>
	</tr>
	<tr>
		<td align="right">申请日期：</td>
		<td align="left">&nbsp;<?=substr($this->contract_info['ctime'],0,10)?></td>
	</tr>
    <tr>
        <td align="right">签约类型：</td>
        <td align="left">&nbsp;<?=(2!=$this->contract_info['sign_type'])? "单签":"集采"?></td>
    </tr>
	<tr>
		<td align="right">签约日期：</td>
		<td align="left">&nbsp;<?=$this->contract_info['sign_date']?></td>
	</tr>
	<tr>
		<td align="right">经销商明细：</td>
		<td align="left">&nbsp;<?=$this->contract_info['dealers_str']?></td>
	</tr>
	<tr>
		<td align="right">合同标准金额：</td>
		<td align="left">&nbsp;<?=$this->contract_info['contract_claim_amount']?></td>
	</tr>
	<tr>
		<td align="right">合同实际金额：</td>
		<td align="left">&nbsp;<?=$this->contract_info['contract_value']?></td>
	</tr>
	<tr>
		<td align="right">整单数量：</td>
		<td align="left">&nbsp;<?=$total_qty?></td>
	</tr>
	<tr>
		<td align="right">合同成本：</td>
		<td align="left">&nbsp;<?=$this->contract_info['contract_cost']?></td>
	</tr>
	<tr>
		<td align="right">应收金额：</td>
		<td align="left">&nbsp;<?=$this->contract_info['receivable_value']?></td>
	</tr>
	<?php if($this->contract_info['receivable_value']==$this->contract_info['received_value']){$color="green";}else{$color="red";}?>
	<tr>
		<td align="right">已收金额：</td>
		<td align="left">&nbsp;<font color="<?=$color?>"><?=$this->contract_info['received_value']?></font></td>
	</tr>
	<tr>
		<td align="right">审批状态：</td>
		<td align="left">&nbsp;<?php if($this->contract_info["allow_edit"]):?>驳回修改<?php else:?><?=$this->statuses[$this->contract_info['status']]?><?php endif;?></td>
	</tr>
	<tr>
		<td align="right">执行状态：</td>
		<td align="left">&nbsp;<?php if(2==$this->contract_info['launch_switcher']){echo "已执行";}elseif(1==$this->contract_info['launch_switcher']){echo "通知执行";}else{echo "未执行";}?></td>
	</tr>
</table>
<br />
<table border="1" width="100%">
	<tr>
		<th>经销商ID</th>
		<th>产品</th>
		<th>刊例单价</th>
		<th>数量</th>
		<th>刊例价</th>
		<th>标准售价</th>
		<th>实际售价</th>
		<th>返点</th>
		<th>服务期限</th>
		<th>托管平台</th>
	</tr>
	<?php foreach($this->sku_info['base_info'] as $val):?>
	<tr>
		<td><?=$val['dealer_id']?></td>
		<td><?=$val['sku_path']['path_name']?>
            <?php if($val['product_id'] == '2'):?>
                <br/><span style="color:red">汇销宝账号：<?=$val['hxb_account']?></span>
            <?php endif;?>
        </td>
		<td><?=$val['unit_price']?></td>
		<td><?=$val['quantity']?></td>
		<td><?=$val['rrp']?></td>
		<td><?=$val['claim_amount']?></td>
		<td><?=$val['actual_pay']?></td>
		<td>
		<?php if(961 == $val['sku_id']):?>
		<?=($val['961_discount'] / $val['actual_pay'] * 100)?>%
		<?php endif;?>
		</td>
		<td><?=$val['start_date']?>至<?=$val['expired_date']?></td>
		<td><?=$this->sku_info['service_info']['str'][$val['cs_id']]?></td>
	</tr>
	<?php endforeach;?>
</table>
<br />
<a name="pay-plan"></a>
<?php if($_SESSION['identity']['userid'] == $this->contract_info['sales_emp_id']):?>
<input type="button" value="编辑回款计划" onclick="window.location.href='/contracts/edit-pay-plans/contract_id/<?=$this->contract_info['contract_id']?>'" />
<br>
<?php endif;?>
<table border="1" width="100%">
	<tr>
		<th>计划回款日期</th>
		<th>金额</th>
		<th>备注</th>
		<th>发票号</th>
		<th>状态</th>
		<?php if("LEVEL-4" == $_SESSION['identity']['level']):?>
		<th>财务操作</th>
		<?php endif;?>
	</tr>
	<?php if($this->pay_plans):?>
	<?php foreach($this->pay_plans as $val):?>
		<tr>
			<td><?=$val['plan_date']?></td>
			<td><?=$val['plan_value']?></td>
			<td><?=$val['tips']?></td>
			<td><?=$val['invoice']?></td>
			<td><?=$val['status']?"<font color='green'>已认款</font>":"未认款"?></td>
			<?php if("LEVEL-4" == $_SESSION['identity']['level']):?>
			<td>
				<?php if(!$val['status'] && in_array($this->contract_info['status'], array(2,3,4))):?>
				<input type="button" value="认款" onclick="window.location.href='/contracts/pay-plan-action/plan_id/<?=$val['plan_id']?>'" />
				<?php endif;?>
			</td>
			<?php endif;?>
		</tr>
	<?php endforeach;?>
	<?php endif;?>
</table>
<br />
<table border="1" width="100%">
	<tr>
		<td align="center" colspan="3"><b>操作日志</b></td>
	</tr>
	<tr>
		<td align="center"><b>时间</b></td>
		<td align="center"><b>操作内容</b></td>
		<td align="center"><b>操作人</b></td>
	</tr>
	<?php if($this->action_logs):?>
	<?php foreach($this->action_logs as $log):?>
	<tr>
		<td align="center"><?=$log['ctime']?></td>
		<td align="center"><?=$log['contents']?></td>
		<td align="center"><?=$log['realName']?></td>
	</tr>
	<?php endforeach;?>
	<?php endif;?>
</table>
<br />
<table border="1" width="100%">
	<tr>
		<td align="center" colspan="3"><b>审批日志</b></td>
	</tr>
	<tr>
		<td align="center"><b>时间</b></td>
		<td align="center"><b>操作内容</b></td>
		<td align="center"><b>操作人</b></td>
	</tr>
	<?php if($this->logs_approval):?>
	<?php foreach($this->logs_approval as $logs_approval):?>
	<tr>
		<td align="center"><?=$logs_approval['ctime']?></td>
		<td align="center">变更为<?php if(99==$logs_approval['act_type']){echo "已执行";}elseif(98==$logs_approval['act_type']){echo "驳回修改";}else{echo $this->statuses[$logs_approval['act_type']];}?><?php if($logs_approval['tips']):?> (<?=$logs_approval['tips']?>)<?php endif;?></td>
		<td align="center"><?=$logs_approval['emp_name']?></td>
	</tr>
	<?php endforeach;?>
	<?php endif;?>
</table>
<br /><br />
<br /><br />
</div>
<br/><br/>
<br/><br/>
</div>
<?php if(7 != $this->contract_info['status'] && in_array($_SESSION['identity']['level'], array("LEVEL-1", "LEVEL-2", "LEVEL-3", "LEVEL-4"))):?>
<div align="center">
	<table width="100%" border="0">
		<tr align="center">
			<?php if("LEVEL-1" == $_SESSION['identity']['level']):?>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #ACCD3C;" onclick="ContractOpt(<?=$this->contract_info['contract_id']?>, 7)">作废</button></td>
			<?php elseif("LEVEL-2" == $_SESSION['identity']['level']):?>
				<?php if($this->contract_info["next_leader_id"] == $_SESSION['identity']['userid'] && 0 == $this->contract_info['status'] && !$this->contract_info['allow_edit']):?>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #ACCD3C;" onclick="ContractOpt(<?=$this->contract_info['contract_id']?>, 1)">通过</button></td>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #f35333;" onclick="ContractOpt(<?=$this->contract_info['contract_id']?>, 0)">驳回</button></td>
				<?php endif;?>
				<?php if($_SESSION['identity']['userid'] ==$this->contract_info['sales_emp_id'] && 0 == $this->contract_info['status']):?>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #ACCD3C;" onclick="ContractOpt(<?=$this->contract_info['contract_id']?>, 7)">作废</button></td>
				<?php endif;?>
			<?php elseif("LEVEL-3" == $_SESSION['identity']['level']):?>
				<?php if(1 == $this->contract_info['status']):?>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #ACCD3C;" onclick="ContractOpt(<?=$this->contract_info['contract_id']?>, 2)">通过</button></td>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #f35333;" onclick="ContractOpt(<?=$this->contract_info['contract_id']?>, 0)">驳回</button></td>
				<?php elseif(2 == $this->contract_info['status']):?>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #f35333;" onclick="ContractOpt(<?=$this->contract_info['contract_id']?>, 0)">驳回</button></td>
				<?php endif;?>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #ACCD3C;" onclick="window.location.href='/contracts/edit-contract-type2/contract_id/<?=$this->contract_info['contract_id']?>'">修改合同</button></td>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #ACCD3C;" onclick="window.location.href='/contracts/edit-contract/contract_id/<?=$this->contract_info['contract_id']?>'">修改状态</button></td>
			<?php elseif("LEVEL-4" == $_SESSION['identity']['level']):?>
				<?php if(2 == $this->contract_info['status']):?>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #f35333;" onclick="ContractOpt(<?=$this->contract_info['contract_id']?>, 0)">驳回</button></td>
				<?php endif;?>
				<td><button style="width: 100px; height: 50px; font-size: 20px; background: #ACCD3C;" onclick="window.location.href='/contracts/edit-contract-type2/contract_id/<?=$this->contract_info['contract_id']?>'">修改合同</button></td>
			<?php endif;?>
		</tr>
	</table>
</div>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<?php endif;?>

<script>
function ContractOpt(contract_id, status)
{
	var msg = "";
	
	if(status == 1 || status == 2)
	{
		var msg = "确认通过此合同吗？";
	}else if(status == 0)
	{
		var msg = "确认驳回此合同吗？";
	}else if(status == 7)
	{
		var msg = "确认作废此合同吗？";
	}
	
	if (confirm(msg)==true){
		if(status != 0)
		{
			$.ajax({
				type: "post",
				url : "/ajax/contract-opt",
				dataType:'json',
				async:false,
				data: {
						'id':contract_id,
						'status':status
					  },
					success: function(json){
						if(json.result == 1) {
							window.location.href = "/contracts/view-contract/contract_id/"+json.contract_id+"/msg/1";
						}else{
							window.location.href = "/contracts/view-contract/contract_id/"+json.contract_id+"/msg/2";
						}
				}
			});
		}else{
			window.location.href = "/contracts/rejection/contract_id/" + contract_id;
		}
	}else{ 
		return false; 
	}
}
</script>